package org.arain.spring.captive.portal.config;

import org.arain.spring.captive.portal.server.UDPHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.handler.codec.dns.DatagramDnsQueryDecoder;
import io.netty.handler.codec.dns.DatagramDnsResponseEncoder;

/**
 * 
 * <p>
 * Title:UDPProtocolInitalizer
 * </p>
 * 
 * @author Arain
 * @date2018年8月10日
 */
@Component
@Qualifier("uDPProtocolInitalizer")
public class UDPProtocolInitalizer extends ChannelInitializer<NioDatagramChannel> {

	@Autowired
	@Qualifier("uDPHandler")
	UDPHandler serverHandler;

	@Override
	protected void initChannel(NioDatagramChannel ch) throws Exception {
		ch.pipeline().addLast(new DatagramDnsQueryDecoder());
		ch.pipeline().addLast(new DatagramDnsResponseEncoder());
		ch.pipeline().addLast(serverHandler);
	}

	public UDPHandler getServerHandler() {
		return serverHandler;
	}

	public void setServerHandler(UDPHandler serverHandler) {
		this.serverHandler = serverHandler;
	}

}
